function [N1 ] = interp_lat_lon(from,to,s,sec)
% this function creates VTLs between 'from' and 'to' every 's' meters.

load lat_lon_sparse

lat_1 = lat(from,:);
lat_2 = lat(to,:); 
lon_1 = lon(from,:);
lon_2 = lon(to,:);

dist1 = latlong_to_feet(lat_1(1,1),lon_1(1,1),lat_2(1,1),lon_2(1,1));
dist2 = latlong_to_feet(lat_1(1,2),lon_1(1,2),lat_2(1,2),lon_2(1,2));

dist1 = unitsratio('m','ft')*dist1;
dist2 = unitsratio('m','ft')*dist2;

N1 = ceil(dist1/s) - 1;
N2 = ceil(dist2/s) - 1;

if N1 ~= N2
    error('N1 and N2 are not the same')
end

if strcmp(sec,'up')
    for j=2:N1+1
    r = (j-1)*s;
    lat_interp(N1+3-j,1) = (r*lat_1(1,1) + (dist1-r)*lat_2(1,1))/dist1;
    lon_interp(N1+3-j,1) = (r*lon_1(1,1) + (dist1-r)*lon_2(1,1))/dist1;
    lat_interp(N1+3-j,2) = (r*lat_1(1,2) + (dist2-r)*lat_2(1,2))/dist2;
    lon_interp(N1+3-j,2) = (r*lon_1(1,2) + (dist2-r)*lon_2(1,2))/dist2;
    end
else
    for j=2:N1+1
    r = (j-1)*s;
    lat_interp(j,1) = ((dist1-r)*lat_1(1,1) + r*lat_2(1,1))/dist1;
    lon_interp(j,1) = ((dist1-r)*lon_1(1,1) + r*lon_2(1,1))/dist1;
    lat_interp(j,2) = ((dist2-r)*lat_1(1,2) + r*lat_2(1,2))/dist2;
    lon_interp(j,2) = ((dist2-r)*lon_1(1,2) + r*lon_2(1,2))/dist2;
    end
end

lat_interp(1,:) = lat(from,:);
lon_interp(1,:) = lon(from,:);
lat_interp(N1+2,:) = lat(to,:);
lon_interp(N1+2,:) = lon(to,:);

lat = lat_interp;
lon = lon_interp;

save('lat_lon_interp','lat','lon')

disp('lat lon have been generated');

return;